import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams.update({"font.size":20})

def get_cwnd_list(filename):
    with open(filename) as f:
        row_list = f.read().splitlines()

    time_list = []
    cwnd_list = []
    for row in row_list:
        if ',' in row:
            time, cwnd = row.split(',')
            time_list.append(time)
            cwnd_list.append(cwnd)
    return time_list, cwnd_list

if __name__ == "__main__":
    exp_path = './loss-wireless-results/'
    filename = exp_path + "cwnd.dat"
    time_list, cwnd_list = get_cwnd_list(filename)

    # plt.figure(figsize=(6, 3))
    plt.plot(time_list, cwnd_list, label = 'BBR')
    plt.xlabel('Time (s)')
    plt.ylabel('CWND (pkt) (1 pkt = 1448B)')
    plt.xticks([])
    plt.yticks([])
    plt.grid()
    # plt.legend(bbox_to_anchor=(0.5, 0.6))
    plt.tight_layout()
    py_file_name = __file__.split('/')[-1].split('.')[0]
    # plt.savefig(f"{exp_path + py_file_name}.png", bbox_inches='tight')
    plt.show()